Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Text

Imports SQLtoASPX.Support


Public Class MasterASPX
    Private TableGen As RawCreateScript
    Private mDatabaseName As String

    Public Sub New(ByVal TableGen As RawCreateScript)
        Me.TableGen = TableGen
    End Sub

    Public Overrides Function ToString() As String
        Dim Spaces As New Space()
        Dim sb As New StringBuilder

        GetFirstAtLineASPX(sb, TableGen)
        sb.AppendLine("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">")


        sb.AppendLine("<html>")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString() & "<head>")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString() & "<title>" & TableGen.TableNameSpaceAfterCapitalLetter & "</title>")
        sb.AppendLine(Spaces.ToString() & "<meta content=""JavaScript"" name=""vs_defaultClientScript"" />")
        sb.AppendLine(Spaces.ToString() & "<meta content=""http://schemas.microsoft.com/intellisense/ie5"" name=""vs_targetSchema"" />")
        sb.AppendLine()

        sb.AppendLine(Spaces.ToString() & "<link href=""PCGStyleSheet.css"" rel=""stylesheet"" type=""text/css"" />")
        sb.AppendLine(Spaces.ToString() & "<link id=""ThemesCSS"" runat=""server"" type=""text/css"" rel=""stylesheet"" />")
        sb.AppendLine()

        If TableGen.IsAnyColumnDate Then
            If TableGen.EditKeyPassing = EditKeyPassingEnum.Inline Then
                'sb.AppendLine(Spaces.ToString() & "<style type=""text/css""> ")
                'Spaces.Inc()
                'sb.AppendLine(Spaces.ToString() & ".ui(-datepicker)")
                'sb.AppendLine(Spaces.ToString() & "{")
                'Spaces.Inc()
                'sb.AppendLine(Spaces.ToString() & "z-index: 1003; /* must be > than popup editor (1002) */")
                'Spaces.Dec()
                'sb.AppendLine(Spaces.ToString() & "}")
                'Spaces.Dec()
                'sb.AppendLine(Spaces.ToString() & "</style>")

            End If
        End If

        ASPXScriptSection(Spaces, sb, TableGen)

        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</head>")

        Select Case TableGen.EditKeyPassing
            Case EditKeyPassingEnum.Inline
                sb.AppendLine(Spaces.ToString() & "<body onload=""body_onLoad()"">")

            Case Else
                sb.AppendLine(Spaces.ToString() & "<body>")

        End Select



        Spaces.Inc()
        sb.AppendLine(Spaces.ToString() & "<form id=""Form1"" method=""post"" runat=""server"">")
        Spaces.Inc()
        Select Case TableGen.EditKeyPassing
            Case EditKeyPassingEnum.Inline
                sb.AppendLine(Spaces.ToString() & "<asp:ScriptManager ID=""ScriptManager1"" runat=""server"">")
                sb.AppendLine(Spaces.ToString() & "</asp:ScriptManager>")
        End Select
        sb.AppendLine(Spaces.ToString() & "<table id=""Table1"" cellspacing=""0"" cellpadding=""0"" width=""90%"" border=""0"" class=""ui-widget-content ui-widget"">")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString() & "<tr>")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString() & "<td align=""right"">")
        Spaces.Inc()

        Dim OutputList As New List(Of String)
        Select Case TableGen.CodeType
            Case CodeTypeEnum.VB2005, CodeTypeEnum.CS2005
                For Each Column As PCGColumn In TableGen.Columns
                    If Column.Search <> "None" Then
                        Spaces.Inc()
                        Select Case Column.DataType.ToUpper
                            Case "DATETIME"
                                Dim dt As String = ""
                                dt = dt & Spaces.ToString() & "<td class=""ui-widget-header"">" & vbCrLf
                                Spaces.Inc()
                                dt = dt & Spaces.ToString() & "From " & Column.ColumnNameDescriptive & vbCrLf
                                Spaces.Dec()
                                dt = dt & Spaces.ToString() & "</td>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<td>" & vbCrLf
                                Spaces.Inc()
                                dt = dt & Spaces.ToString() & "<" & Column.ControlTypeNameSearch & " ID=""" & Column.ControlNameSearch("From") & """ runat=""server"" Width=""100px""></" & Column.ControlTypeNameSearch & ">&nbsp;" & vbCrLf
                                Spaces.Dec()
                                dt = dt & Spaces.ToString() & "</td>" & vbCrLf
                                OutputList.Add(dt)

                                dt = ""
                                dt = dt & Spaces.ToString() & "<td class=""ui-widget-header"">" & vbCrLf
                                Spaces.Inc()
                                dt = dt & Spaces.ToString() & "To " & Column.ColumnNameDescriptive & vbCrLf
                                Spaces.Dec()
                                dt = dt & Spaces.ToString() & "</td>" & vbCrLf

                                dt = dt & Spaces.ToString() & "<td>" & vbCrLf
                                Spaces.Inc()
                                dt = dt & Spaces.ToString() & "<" & Column.ControlTypeNameSearch & " ID=""" & Column.ControlNameSearch("To") & """ runat=""server"" Width=""100px""></" & Column.ControlTypeNameSearch & ">&nbsp;" & vbCrLf
                                Spaces.Dec()
                                dt = dt & Spaces.ToString() & "</td>" & vbCrLf

                                OutputList.Add(dt)
                            Case "BIT"
                                Dim dt As String = ""
                                dt = dt & Spaces.ToString() & "<td class=""ui-widget-header"">" & vbCrLf
                                dt = dt & Spaces.ToString() & "" & Column.ColumnNameDescriptive & "</td>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<td>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<asp:DropDownList ID=""" & Column.ControlNameSearch() & """ runat=""server"">" & vbCrLf
                                dt = dt & Spaces.ToString() & "<asp:ListItem></asp:ListItem>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<asp:ListItem>Checked</asp:ListItem>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<asp:ListItem>Unchecked</asp:ListItem>" & vbCrLf
                                dt = dt & Spaces.ToString() & "</asp:DropDownList></td>" & vbCrLf

                                OutputList.Add(dt)
                            Case Else
                                Dim dt As String = ""
                                dt = dt & Spaces.ToString() & "<td class=""ui-widget-header"">" & vbCrLf
                                dt = dt & Spaces.ToString() & "" & Column.ColumnNameDescriptive & "</td>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<td>" & vbCrLf
                                dt = dt & Spaces.ToString() & "<" & Column.ControlTypeNameSearch & " ID=""" & Column.ControlNameSearch() & """ runat=""server"" "
                                If Column.LinkTableName.Length > 0 And Column.LinkTableKey.Length > 0 And Column.LinkTableValue.Length > 0 Then
                                    dt = dt & "AppendDataBoundItems=""true"""
                                End If
                                dt = dt & ">"
                                If Column.LinkTableName.Length > 0 And Column.LinkTableKey.Length > 0 And Column.LinkTableValue.Length > 0 Then
                                    dt = dt & "<asp:ListItem Text="""" Value=""""></asp:ListItem>"
                                End If
                                dt = dt & "</" & Column.ControlTypeNameSearch & "></td>" & vbCrLf
                                OutputList.Add(dt)
                        End Select
                        Spaces.Dec()
                        Spaces.Dec()
                    End If

                Next
        End Select

        Dim ButtonText As String = ""

        Select Case TableGen.EditKeyPassing
            Case EditKeyPassingEnum.Inline
                sb.AppendLine(Spaces.ToString & "<input type=""button"" name=""cmdAddNew"" value=""Add New"" id=""cmdAddNew""/>")

                'Button = New ASPXButton(TableGen.CodeType, "AddNew", False)
            Case Else
                Dim Button As ASPXButton = New ASPXButton(TableGen.CodeType, "AddNew")
                ButtonText = Button.ToString
        End Select

        If OutputList.Count > 0 Then
            Spaces.Inc()
            Spaces.Inc()
            Spaces.Inc()
            Spaces.Inc()
            Spaces.Inc()
            Spaces.Inc()

            sb.AppendLine(Spaces.ToString() & "<table style=""width: 100%"">")


            For i As Integer = 0 To OutputList.Count - 1 Step 2
                Spaces.Inc()

                sb.AppendLine(Spaces.ToString() & "<tr>")
                Spaces.Inc()
                sb.Append(OutputList(i))
                If OutputList.Count - 1 >= i + 1 Then
                    sb.Append(OutputList(i + 1))
                Else
                    sb.AppendLine(Spaces.ToString & "<td>&nbsp;</td><td>&nbsp;</td>")
                End If

                If i = 0 Then

                    sb.AppendLine(Spaces.ToString & "<td>")
                    Spaces.Inc()

                    HTMLCboTheme(Spaces, sb, TableGen)

                    Dim cmdSearch As New ASPXButton(TableGen.CodeType, "Search")
                    sb.AppendLine(Spaces.ToString & cmdSearch.ToString)

                    If OutputList.Count < 3 Then
                        sb.AppendLine(Spaces.ToString & ButtonText)
                    End If
                    Spaces.Dec()
                    sb.AppendLine(Spaces.ToString & "</td>")
                ElseIf i = 2 Then
                    sb.AppendLine(Spaces.ToString & "<td>" & ButtonText & "</td>")
                Else
                    sb.AppendLine(Spaces.ToString & "<td>&nbsp;</td>")
                End If
                Spaces.Dec()
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</tr>")

            Next

            sb.AppendLine(Spaces.ToString() & "</table>")

        Else
            HTMLCboTheme(Spaces, sb, TableGen)

            sb.AppendLine(Spaces.ToString & ButtonText)
        End If


        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</td>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</tr>")
        sb.AppendLine(Spaces.ToString() & "<tr>")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString() & "<td>")
        Spaces.Inc()

        Select Case TableGen.Paging
            Case PagingEnum.Basic
            Case Else
                sb.AppendLine(Spaces.ToString() & "<asp:Label ID=""lblRecordsFound"" runat=""server""></asp:Label>")
        End Select
        Select Case TableGen.ViewType
            Case ViewTypeEnum.GridView
                sb.Append(Spaces.ToString)
                sb.Append("<asp:GridView ID=""grd"" runat=""server"" AutoGenerateColumns=""False"" CssClass=""PCG-Content""")
                Select Case TableGen.CodeType
                    Case CodeTypeEnum.CS2005
                        Select Case TableGen.EditKeyPassing
                            Case EditKeyPassingEnum.Inline
                            Case Else
                                sb.Append(" OnRowCommand=""grd_OnRowCommand""")
                        End Select

                End Select

                Select Case TableGen.CodeType
                    Case CodeTypeEnum.CS2005
                        If TableGen.Paging = PagingEnum.Basic Then
                            sb.Append(" OnPageIndexChanging=""grd_PageIndexChanging""")
                        End If
                End Select

                Select Case TableGen.CodeType
                    Case CodeTypeEnum.CS2005
                        If TableGen.Sorting Then
                            sb.Append(" OnSorting=""grd_Sorting""")
                        End If
                End Select

                Dim CanOnRowDataBound As Boolean = False
                Select Case TableGen.CodeType
                    Case CodeTypeEnum.CS2005
                        Select Case TableGen.Paging
                            Case PagingEnum.HighSpeed
                                Select Case TableGen.ViewType
                                    Case ViewTypeEnum.GridView
                                        CanOnRowDataBound = True
                                End Select
                        End Select
                        Select Case TableGen.EditKeyPassing
                            Case EditKeyPassingEnum.Inline
                                CanOnRowDataBound = True
                        End Select
                End Select



                If CanOnRowDataBound Then
                    sb.Append(" OnRowDataBound=""grd_RowDataBound""")
                    If TableGen.Sorting Then
                        sb.Append(" OnRowCreated=""grd_RowCreated""")
                    End If
                End If


                If TableGen.Paging = PagingEnum.Basic Then
                    sb.Append(" AllowPaging=""true""")
                End If

                Select Case TableGen.ViewType
                    Case ViewTypeEnum.GridView
                        If TableGen.Sorting Then
                            sb.Append(" AllowSorting=""true""")
                        End If
                End Select

                sb.AppendLine(">")
            Case ViewTypeEnum.CodeBehind
                    Select Case TableGen.CodeType
                        Case CodeTypeEnum.VB2005
                            sb.AppendLine(Spaces.ToString() & "<asp:Table ID=""grd"" runat=""server"" cellspacing=""0"" rules=""all"" border=""1"" cssClass=""ui-widget-content""></asp:Table>")
                        Case CodeTypeEnum.CS2005
                            sb.AppendLine(Spaces.ToString() & "<asp:Table ID=""grd"" runat=""server"" cellspacing=""0"" rules=""all"" border=""1"" cssClass=""ui-widget-content""></asp:Table>")
                    End Select
            Case ViewTypeEnum.Repeater
                    Select Case TableGen.CodeType
                        Case CodeTypeEnum.VB2005
                            sb.AppendLine(Spaces.ToString() & "<asp:Repeater ID=""grd"" runat=""server"">")
                        Case CodeTypeEnum.CS2005
                            Dim RepeaterLine As String = "<asp:Repeater ID=""grd"" runat=""server"""
                            Select Case TableGen.Paging
                                Case PagingEnum.HighSpeed
                                    RepeaterLine = RepeaterLine & " OnItemCreated=""grd_ItemCreated"""
                            End Select

                            RepeaterLine = RepeaterLine & ">"
                            sb.AppendLine(Spaces.ToString & RepeaterLine)
                    End Select
        End Select

        If TableGen.ViewType = ViewTypeEnum.GridView Then
            Select Case TableGen.CodeType
                Case CodeTypeEnum.CS2005, CodeTypeEnum.VB2005
                    Spaces.Inc()
                    sb.AppendLine(Spaces.ToString() & "<Columns>")
                    Spaces.Inc()
            End Select
        Else
            '
        End If

        If TableGen.ViewType = ViewTypeEnum.GridView Then
            sb.AppendLine(Spaces.ToString() & "<asp:BoundField DataField=""" & TableGen.AutoNumberColumn & """ >")
            Spaces.Inc()
            sb.AppendLine(Spaces.ToString() & "<ItemStyle CssClass=""BoundFieldItemStyleHidden"" />")
            sb.AppendLine(Spaces.ToString() & "<HeaderStyle CssClass=""BoundFieldHeaderStyleHidden"" />            ")
            Spaces.Dec()
            sb.AppendLine(Spaces.ToString() & "</asp:BoundField>")
        End If
        'End If

        Select Case TableGen.ViewType
            Case ViewTypeEnum.GridView
                For Each Column As PCGColumn In TableGen.Columns
                    If Column.DisplayInGrid = True Then
                        sb.Append(Spaces.ToString() & "<asp:BoundField DataField=""" & Column.BoundField & """ HeaderText=""" & Column.ColumnNameDescriptive & """")

                        Select Case TableGen.Sorting
                            Case True
                                sb.Append(" SortExpression=""" & Column.SortBoundField(TableGen) & """")
                        End Select
                        sb.AppendLine("></asp:BoundField>")
                    End If
                Next
            Case ViewTypeEnum.Repeater
                Spaces.Inc()
                sb.AppendLine(Spaces.ToString() & "<HeaderTemplate>")
                Spaces.Inc()
                sb.AppendLine(Spaces.ToString() & "<table class=""ui-widget-content PCG-Content"">")
                Spaces.Inc()
                sb.AppendLine(Spaces.ToString() & "<tr class=""ui-widget-header"">")
                Spaces.Inc()
                For Each Column As PCGColumn In TableGen.Columns
                    If Column.DisplayInGrid = True Then
                        sb.AppendLine(Spaces.ToString() & "<td>" & Column.ColumnNameDescriptive & "</td>")
                    End If
                Next
                sb.AppendLine(Spaces.ToString() & "<td></td>")
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</tr>")
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</HeaderTemplate>")
                sb.AppendLine(Spaces.ToString() & "<ItemTemplate>")
                Spaces.Inc()
                sb.AppendLine(Spaces.ToString() & "<tr>")
                Spaces.Inc()
                For Each Column As PCGColumn In TableGen.Columns
                    If Column.DisplayInGrid = True Then
                        sb.AppendLine(Spaces.ToString() & "<td>")
                        Spaces.Inc()
                        sb.AppendLine(Spaces.ToString() & "<%#DataBinder.Eval(Container.DataItem, """ & Column.BoundField & """)%>")
                        Spaces.Dec()
                        sb.AppendLine(Spaces.ToString() & "</td>")
                    End If
                Next
                sb.AppendLine(Spaces.ToString() & "<td>")
        End Select

        Select Case TableGen.ViewType
            Case ViewTypeEnum.GridView

                Select Case TableGen.EditKeyPassing
                    Case EditKeyPassingEnum.Inline
                        sb.AppendLine(Spaces.ToString() & "<asp:BoundField HeaderText=""Edit"" />")
                        
                    Case Else
                        sb.AppendLine(Spaces.ToString() & "<asp:ButtonField ButtonType=""Button"" Text=""Edit"">")
                        Spaces.Inc()
                        sb.AppendLine(Spaces.ToString() & "<ControlStyle CssClass=""GridEditButton"" />")
                        Spaces.Dec()
                        sb.AppendLine(Spaces.ToString() & "</asp:ButtonField>")
                End Select
        End Select
        Select Case TableGen.ViewType
            Case ViewTypeEnum.Repeater
                sb.AppendLine(Spaces.ToString() & "<input type=""button"" value=""Edit"" class=""GridEditButton"" onclick=""GridClick(<%#DataBinder.Eval(Container.DataItem, """ & TableGen.AutoNumberColumn & """)%>);"" />")
                'sb.Append(Spaces.ToString() & "<a href=")
                'sb.Append("""Edit" & TableGen.TableName & ".aspx?ID=")
                'sb.Append("<%#DataBinder.Eval(Container.DataItem, """ & TableGen.AutoNumberColumn & """)%>")
                'sb.Append("""")
                'sb.Append(" class=""GridEditButton""")
                'sb.AppendLine(">Edit</a>")
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</td>")
        End Select

        Select Case TableGen.ViewType
            Case ViewTypeEnum.GridView
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</Columns>")
                sb.AppendLine(Spaces.ToString() & "<HeaderStyle CssClass=""ui-widget-header""  />")
                sb.AppendLine(Spaces.ToString() & "<RowStyle CssClass=""ui-widget-content"" />")
                sb.AppendLine(Spaces.ToString() & "<AlternatingRowStyle/>")
            Case ViewTypeEnum.Repeater
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</tr>")
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</ItemTemplate>")

                Dim OUtput As String = sb.ToString
                Dim StartLoc As Long = InStr(OUtput, "<ItemTemplate>", CompareMethod.Text)
                Dim Stuff As String = Right(OUtput, Len(OUtput) - StartLoc + 1)
                Stuff = Replace(Stuff, "<ItemTemplate>", "<AlternatingItemTemplate>", , , CompareMethod.Text)
                Stuff = Replace(Stuff, "</ItemTemplate>", "</AlternatingItemTemplate>", , , CompareMethod.Text)
                Stuff = Replace(Stuff, "class=""PCGEvenRow""", "class=""PCGOddRow""", , , CompareMethod.Text)
                sb.Append(Stuff)

                sb.AppendLine(Spaces.ToString() & "<FooterTemplate>")
                Spaces.Inc()
                sb.AppendLine(Spaces.ToString() & "</table>")
                Spaces.Dec()
                sb.AppendLine(Spaces.ToString() & "</FooterTemplate>")

            Case ViewTypeEnum.CodeBehind
        End Select

        Spaces.Dec()
        Select Case TableGen.CodeType
            Case CodeTypeEnum.VB2005
                Select Case TableGen.ViewType
                    Case ViewTypeEnum.GridView
                        sb.AppendLine(Spaces.ToString() & "</asp:GridView>   ")
                    Case ViewTypeEnum.Repeater
                        sb.AppendLine(Spaces.ToString() & "</asp:Repeater>   ")
                        Select Case TableGen.EditKeyPassing
                            Case EditKeyPassingEnum.Inline
                            Case Else
                                sb.AppendLine(Spaces.ToString() & "<asp:Button ID=""cmdLoad"" runat=""server"" Text=""Button"" Style=""display:none"" />")
                                sb.AppendLine(Spaces.ToString() & "<asp:HiddenField runat=""server"" ID=""RowClick"" />")
                        End Select
                    Case ViewTypeEnum.CodeBehind
                        Select Case TableGen.EditKeyPassing
                            Case EditKeyPassingEnum.Inline
                            Case Else

                                sb.AppendLine(Spaces.ToString() & "<asp:Button ID=""cmdLoad"" runat=""server"" Text=""Button"" Style=""display:none"" />")
                                sb.AppendLine(Spaces.ToString() & "<asp:HiddenField runat=""server"" ID=""RowClick"" />")
                        End Select
                End Select
            Case CodeTypeEnum.CS2005
                Select Case TableGen.ViewType
                    Case ViewTypeEnum.GridView
                        sb.AppendLine(Spaces.ToString() & "</asp:GridView>   ")
                    Case ViewTypeEnum.Repeater
                        sb.AppendLine(Spaces.ToString() & "</asp:Repeater>   ")
                        Select Case TableGen.EditKeyPassing
                            Case EditKeyPassingEnum.Inline
                            Case Else

                                sb.AppendLine(Spaces.ToString() & "<asp:Button ID=""cmdLoad"" runat=""server"" Text=""Button"" Style=""display:none""  OnClick=""cmdLoad_Click"" />")
                                sb.AppendLine(Spaces.ToString() & "<asp:HiddenField runat=""server"" ID=""RowClick"" />")
                        End Select
                    Case ViewTypeEnum.CodeBehind
                        Select Case TableGen.EditKeyPassing
                            Case EditKeyPassingEnum.Inline
                            Case Else

                                sb.AppendLine(Spaces.ToString() & "<asp:Button ID=""cmdLoad"" runat=""server"" Text=""Button"" Style=""display:none""  OnClick=""cmdLoad_Click"" />")
                                sb.AppendLine(Spaces.ToString() & "<asp:HiddenField runat=""server"" ID=""RowClick"" />")
                        End Select
                End Select
        End Select

        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</td>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</tr>")

        If TableGen.Paging = PagingEnum.HighSpeed Then
            sb.AppendLine(Spaces.ToString() & "<tr>")
            Spaces.Inc()
            sb.AppendLine(Spaces.ToString() & "<td>")
            Spaces.Inc()

            Dim cmdFirst As New ASPXButton(TableGen.CodeType, "First")
            sb.AppendLine(Spaces.ToString() & cmdFirst.ToString)
            'sb.Append(Spaces.ToString() & "<asp:LinkButton ID=""cmdFirst"" runat=""server""")
            'Select Case TableGen.CodeType
            '    Case CodeTypeEnum.CS2005
            '        sb.Append(" onclick=""cmdFirst_Click""")
            'End Select
            'sb.AppendLine(">First</asp:LinkButton>&nbsp;&nbsp;")

            Dim cmdPrevious As New ASPXButton(TableGen.CodeType, "Previous")
            sb.AppendLine(Spaces.ToString & cmdPrevious.ToString)
            'sb.Append(Spaces.ToString() & "<asp:LinkButton ID=""cmdPrevious"" runat=""server""")
            'Select Case TableGen.CodeType
            '    Case CodeTypeEnum.CS2005
            '        sb.Append(" onclick=""cmdPrevious_Click""")
            'End Select
            'sb.AppendLine(">Previous</asp:LinkButton>&nbsp;&nbsp;")
            sb.AppendLine(Spaces.ToString() & "<asp:Label ID=""lblPageNumber"" runat=""server""></asp:Label>&nbsp;&nbsp;")
            'sb.Append(Spaces.ToString() & "<asp:LinkButton ID=""cmdNext"" runat=""server""")
            'Select Case TableGen.CodeType
            '    Case CodeTypeEnum.CS2005
            '        sb.Append(" onclick=""cmdNext_Click""")
            'End Select
            'sb.AppendLine(">Next</asp:LinkButton>&nbsp;&nbsp;")
            Dim cmdNext As New ASPXButton(TableGen.CodeType, "Next")
            sb.AppendLine(Spaces.ToString & cmdNext.ToString)

            'sb.Append(Spaces.ToString() & "<asp:LinkButton ID=""cmdLast"" runat=""server""")
            'Select Case TableGen.CodeType
            '    Case CodeTypeEnum.CS2005
            '        sb.Append(" onclick=""cmdLast_Click""")
            'End Select
            'sb.AppendLine(">Last</asp:LinkButton>")
            Dim cmdLast As New ASPXButton(TableGen.CodeType, "Last")
            sb.AppendLine(Spaces.ToString & cmdLast.ToString)

            Spaces.Dec()
            sb.AppendLine(Spaces.ToString() & "</td>")
            Spaces.Dec()
            sb.AppendLine(Spaces.ToString() & "</tr>")
        End If

        Spaces.Dec()

        sb.AppendLine(Spaces.ToString() & "</table>")
        ASPXUpdateDialog(Spaces, sb, TableGen)
        ASPXUpdateHiddenFields(Spaces, sb, TableGen)


        'sb.AppendLine("<a id=""various2"" href=""#dialog"">Inline - modal window</a>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</form>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</body>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString() & "</html>")
        Return sb.ToString
    End Function

    Private Function GetMasterAddNewClick(ByVal TableGen As RawCreateScript) As String
        Dim sb As New StringBuilder

        sb.AppendLine()
        Select Case TableGen.CodeType
            Case CodeTypeEnum.VB2005
                sb.AppendLine("    Protected Sub cmdAddNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAddNew.Click")
            Case CodeTypeEnum.CS2005
                sb.AppendLine("    protected void cmdAddNew_Click(object sender, EventArgs e)")
                sb.AppendLine("    {")
        End Select

        If TableGen.EditKeyPassing = EditKeyPassingEnum.Session Then

            Select Case TableGen.CodeType
                Case CodeTypeEnum.VB2005
                    sb.AppendLine("        Session(""Edit" & TableGen.TableName & "." & TableGen.AutoNumberColumn & """) = """"")
                Case CodeTypeEnum.CS2005
                    sb.AppendLine("        Session[""Edit" & TableGen.TableName & "." & TableGen.AutoNumberColumn & """] = """";")
            End Select
        Else
            'do nothing
        End If

        sb.AppendLine("        Response.Redirect(""Edit" & TableGen.OutputFileName & ".aspx"")" & EndStatement(TableGen))

        Select Case TableGen.CodeType
            Case CodeTypeEnum.VB2005
                sb.AppendLine("    End Sub")
                sb.AppendLine("")
            Case CodeTypeEnum.CS2005
                sb.AppendLine("    }")
        End Select

        Return sb.ToString
    End Function

End Class
